from utils import DataBlockVariable, PLCDataType

# PLC连接配置
PLC_CONFIG = {
    "host": "192.168.1.1",     # PLC IP地址
    "rack": 0,                 # S7机架号
    "slot": 1,                 # S7插槽号
    "timeout": 5               # 连接超时时间（秒）
}

# 测试结果DB号
TEST_RESULT_DB_NUMBER = 1

# 信息项DB号
SCAN_DB_NUMBER = 2

# 测试
DUMMY_DB_NUMBER = 1


DATA_BLOCK_VARIABLES = {
    "Motor_id": DataBlockVariable(
        name="电机序号",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=0,
        data_type=PLCDataType.STRING,
        unit="",
        description="电机序号"
    ),
    "EDCU_id": DataBlockVariable(
        name="门控器序号",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=256,
        data_type=PLCDataType.STRING,
        unit="",
        description="门控器序号"
    ),
    "Wiring_barcode": DataBlockVariable(
        name="线束条码",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=512,
        data_type=PLCDataType.STRING,
        unit="",
        description="线束条码"
    ),
    "Screw_assembly": DataBlockVariable(
        name="螺杆装配",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=768,
        bit_offset=0,
        data_type=PLCDataType.BOOL,
        unit="",
        description="螺杆装配完成标志"
    ),
    "Dielectric_test": DataBlockVariable(
        name="耐压测试",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=768,
        bit_offset=1,
        data_type=PLCDataType.BOOL,
        unit="",
        description="耐压测试结果"
    ),
    "Obstacle_test": DataBlockVariable(
        name="防夹测试",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=768,
        bit_offset=2,
        data_type=PLCDataType.BOOL,
        unit="",
        description="防夹测试结果"
    ),
    "Grider_assembly": DataBlockVariable(
        name="横梁装配",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=768,
        bit_offset=3,
        data_type=PLCDataType.BOOL,
        unit="",
        description="横梁装配完成标志"
    ),
    "Open_time": DataBlockVariable(
        name="开门时间",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=770,
        data_type=PLCDataType.REAL,
        unit="s",
        description="开门所用时间"
    ),
    "Push_force": DataBlockVariable(
        name="推力测试",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=774,
        data_type=PLCDataType.DWORD,
        unit="N",
        description="推力测试结果"
    ),
    "Bracket_assembly_wiring": DataBlockVariable(
        name="支架装配机构布线",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=778,
        data_type=PLCDataType.BOOL,
        unit="",
        description="支架装配机构布线完成标志"
    ),
    "Close_time": DataBlockVariable(
        name="关门时间",
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=780,
        data_type=PLCDataType.REAL,
        unit="s",
        description="关门所用时间"
    ),
    "Pull_force": DataBlockVariable(
        name="拉力测试", #拉力测试实际值是浮点，需要/100，目前集成在前端显示时进行具体运算
        db_number=TEST_RESULT_DB_NUMBER,
        start_offset=784,
        data_type=PLCDataType.DWORD,
        unit="N",
        description="拉力测试结果"
    ),
        
    "project_name": DataBlockVariable(
        name="项目名称",
        db_number=SCAN_DB_NUMBER,
        start_offset=0,
        data_type=PLCDataType.STRING,
        unit="",
        description="项目名称"
    ),
    "product_number": DataBlockVariable(
        name="产品编号",
        db_number=SCAN_DB_NUMBER,
        start_offset=256,
        data_type=PLCDataType.STRING,
        unit="",
        description="产品编号"
    ),
    "station_name": DataBlockVariable(
        name="工位名称",
        db_number=SCAN_DB_NUMBER,
        start_offset=512,
        data_type=PLCDataType.STRING,
        unit="",
        description="工位名称"
    ),
    "count": DataBlockVariable(
        name="列数",
        db_number=SCAN_DB_NUMBER,
        start_offset=768,
        data_type=PLCDataType.STRING,
        unit="",
        description="列数"
    ),
    "trace_barcode": DataBlockVariable(
        name="追溯条码",
        db_number=SCAN_DB_NUMBER,
        start_offset=1024,
        data_type=PLCDataType.STRING,
        unit="",
        description="追溯条码"
    ),
    "operator": DataBlockVariable(
        name="操作人员",
        db_number=SCAN_DB_NUMBER,
        start_offset=1280,
        data_type=PLCDataType.WSTRING,
        unit="",
        description="操作人员"
    ),
    "rtp_version": DataBlockVariable(
        name="RTP版本",
        db_number=SCAN_DB_NUMBER,
        start_offset=1792,
        data_type=PLCDataType.STRING,
        unit="",
        description="RTP版本号"
    ),
    "software_version": DataBlockVariable(
        name="软件版本",
        db_number=SCAN_DB_NUMBER,
        start_offset=2048,
        data_type=PLCDataType.STRING,
        unit="",
        description="软件版本号"
    ),
    "product_status": DataBlockVariable(
        name="产品状态",
        db_number=SCAN_DB_NUMBER,
        start_offset=2304,
        data_type=PLCDataType.STRING,
        unit="",
        description="产品状态"
    ),
    "qualified_count": DataBlockVariable(
        name="合格品统计",
        db_number=SCAN_DB_NUMBER,
        start_offset=2560,
        data_type=PLCDataType.STRING,
        unit="",
        description="合格品统计"
    ),
    "unqualified_count": DataBlockVariable(
        name="不良品统计",
        db_number=SCAN_DB_NUMBER,
        start_offset=2816,
        data_type=PLCDataType.DINT,
        unit="",
        description="不良品统计"
    ),
    "concession_count": DataBlockVariable(
        name="让步放行统计",
        db_number=SCAN_DB_NUMBER,
        start_offset=2820,
        data_type=PLCDataType.STRING,
        unit="",
        description="让步放行统计"
    )
}

SCANNER_BOLCK_VARIABLES= {
    "ScannerString": DataBlockVariable(
    name="扫码枪信息",
    db_number=30,
    start_offset=0,
    data_type=PLCDataType.STRING,
    unit="",
    description="扫码枪信息"
),
}

# # 测试
# DATA_BLOCK_VARIABLES = {
#     "teststr": DataBlockVariable(
#         name="",
#         db_number=DUMMY_DB_NUMBER,
#         start_offset=0,
#         data_type=PLCDataType.STRING,
#         unit="",
#         description=""
#     ),
#     "testreal": DataBlockVariable(
#         name="",
#         db_number=DUMMY_DB_NUMBER,
#         start_offset=256,
#         data_type=PLCDataType.REAL,
#         unit="",
#         description=""
#     ),
# }


# 监控配置
MONITOR_CONFIG = {
    "variables": list(DATA_BLOCK_VARIABLES.keys()),  # 要监控的变量
}